package web.action.base;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import web.common.entity.User;


import com.opensymphony.xwork2.ActionSupport;

/**
 * 
* 项目名称：ebs 
* @ClassName: BaseAction
* @author ZK JIA<br>
* 创建时间： 2013-11-6 上午10:31:24<br>
* @version 1.1<br>
* 描述: TODO(这里用一句话描述这个类的作用)<br>
 */
public class BaseAction extends ActionSupport implements ServletRequestAware,ServletResponseAware {

private static Logger logger = Logger.getLogger(BaseAction.class);
	
	private static final long serialVersionUID = 1L;
	
	public HttpServletRequest request;
	
	public HttpServletResponse response;
	//用于存放返回消息
	public Map msgMap = new HashMap();
	
	public String DEFAULT_MESSAGE = "msg";
	
	public JSONObject result;
	
	/**
	 * 
	* @Title: addUserToSession
	* @param user
	* @return void    返回类型<br>
	* 创建者:ZK JIA  创建时间：2013-11-6 上午10:35:54 <br>
	* 修改者:ZK JIA  修改时间：2013-11-6 上午10:35:54<br>
	* 描述: 将用户添加到session
	 */
	public void addUserToSession(User user) {
	   request.getSession().setAttribute("user", user);
		logger.debug("add user to session session");
		
	}
	
	/**
	 * 
	* @Title: getCurrentUser
	* @return
	* @return User    返回类型<br>
	* 创建者:ZK JIA  创建时间：2013-11-6 上午10:36:27 <br>
	* 修改者:ZK JIA  修改时间：2013-11-6 上午10:36:27<br>
	* 描述: 从session中获取用户信息
	 */
	public User getCurrentUser() {
		
		return (User) this.request.getSession().getAttribute("user");
		
	}
	
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public Map getMsgMap() {
		return msgMap;
	}

	public void setMsgMap(Map msgMap) {
		this.msgMap = msgMap;
	}

	public JSONObject getResult() {
		return result;
	}

	public void setResult(JSONObject result) {
		this.result = result;
	}
	/**
	 * 
	* @Title: logoPage
	* @return
	* @return String    返回类型<br>
	* 创建者:ZK JIA  创建时间：2013-11-6 上午10:42:24 <br>
	* 修改者:ZK JIA  修改时间：2013-11-6 上午10:42:24<br>
	* 描述: 默认方法返回到首页
	 */
    public String logoPage(){
    	
    	return SUCCESS;
    }

}
